#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
    string a,b;
    cin>>a>>b;
    unordered_map<char, pair<int,int>>mp;
    unordered_map<char, bool>f;
    pair<int, int>ans={a.size()-1,0};
    bool flag=0;
    if(a.size()==1||b.size()==1)
    {
        cout<<-1<<endl;
        return;
    }
    for(int i=1;i<a.size();i++)
    {
        if(f[a[i]])continue;
        else f[a[i]]=1;
        for(int j=b.size()-2;j>0;j--)
        {
            if(a[i]==b[j])
            {
                if(!flag)flag=1;
                mp[a[i]].first=i,mp[a[i]].second=j;
                break;
            }
        }
    }
    for(auto z:mp)
    {
        int x=z.second.first,y=z.second.second;
        if(ans.first-ans.second>x-y)ans.first=x,ans.second=y;
    }
    if(ans.first==a.size()-1&&ans.second==0&&a[ans.first]!=b[ans.second])cout<<-1<<endl;
    else
    {
        for(int i=0;i<=ans.first;i++)cout<<a[i];
        for(int i=ans.second+1;i<b.size();i++)cout<<b[i];
        cout<<endl;
    }
}
signed main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    int T=1;
    //cin>>T;
    while(T--)
    {
       solve();
    }
    return 0;
}